#include "fliter.h"
#include "ringbuff.h"
#include "log.h"
//高频振荡：
unsigned char x[20] = {100,110,103,102,104,106,92,96,95,92,104,97,92,89,103,107,98,96,94,96};

//随机干扰信号
unsigned char y[20] = {100,170,120,185,110,112,90,200,93,102,109,97,90,82,87,200,95,94,94,96};
unsigned char out;
void test_ringbuff()
{
	unsigned char *c = "abcdef";
	unsigned char *p = malloc(sizeof(unsigned char));
	
	RingBuff_handle rb = createRingBuff(10);
	writeRingBuff(rb,c,strlen(c));
	readRingBuff(rb,p,5);
	LOGI("%s",p);
	deleteRingBuff(rb);
}
void testRecurrenceAverFliter()
{
	int i;
	
	for(i = 0;i<20;i++)
	{
		out = RecurrenceAverFliter(y[i]);
		
		LOGI("递推平均算法 out = %d\r\n",out);
	}

}

void testMidAverFliter()
{
	out = MidAverFliter(y);
	LOGI("中位值平均算法 out = %d\r\n",out);
}

void testMiddlevalueFliter()
{
	out = MiddlevalueFliter(y);
	LOGI("中位值算法 out = %d\r\n",out);
	
}

void testAverageFliter()
{
	out = AverageFliter(y);
	LOGI("算术平均算法 out = %d\r\n",out);
	
}

void testAmplitudeLimiterFliter()
{
	int i;
	for(i = 0;i<20;i++)
	{
		out = RecurrenceAverFliter(y[i]);
		LOGI("限幅算法 out = %d\r\n",out);
	}

}

void test_fliter()
{

	testAmplitudeLimiterFliter();
	testAverageFliter();
	testMiddlevalueFliter();
	testMidAverFliter();
	testRecurrenceAverFliter();
}

void main()
{
	LOGW("start");
	test_ringbuff();
	test_fliter();
	LOGW("exit");
}